/*!
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 *    Author: flareguner
 *    E-Mail: flareguner@gmail.com
 *    Years: 2010-2011
 */


#ifndef POPUP_H
#define POPUP_H

#include <QtGui/QFrame>
#include <QtGui/QCursor>
#include <QtGui/QClipboard>

#include <QtCore/QTimer>




/*!
 * This class provide wrapper on QFrame class
 * with some popup-specific features and eyecandies, OMG!
 */


class QTextBrowser;
class QToolBar;
class QAction;

class Popup : public QFrame
{
    Q_OBJECT
public:
    explicit Popup(QWidget *parent = 0);
    ~Popup();

    //! show @arg text into current mouse location
    void popup(const QString &text);

    //! show @arg text into @arg pos location
    void popup(const QPoint &pos, const QString &text);

    //! disable-enable toolbar
    void setShowToolbar(bool flag);

    /*! Hide interval in @arg msecs.
     * if 0 - popup will be hidden only
     * by mouse click on them.
     */
    void setHideInterval(const int msecs) {
	m_timer.setInterval(msecs);
    }

//    void setTextFont(const QFont &font);
    //! true if popup shown
//    bool isPopuped() {
//	return !isHidden();
//    }


    void setCursorPositionLocked(bool b) {
        m_pos_locked = b;
    }
private slots:
    void updateCursorPos();
protected:
    void mouseReleaseEvent(QMouseEvent *);
    void keyReleaseEvent(QKeyEvent *);
    void leaveEvent(QEvent *);
private:
    //Data
    QTimer m_timer;


    bool m_pos_locked;
    QPoint m_cursor_pos;
    QClipboard *m_clipboard;

    QTextBrowser *resultText;
    QToolBar *toolBar;
    QAction *pronounceAction;
private slots:jhj
    void timeoutHandler();
signals:
    void pronounceRequested();
};

#endif // POPUP_H
